package com.taotao.tools.springmvc.csrf;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;


/**
 * 生成token接口
 * 先获取token,将获取的token放入请求header中csrf-token
 */
@RestController
@RequestMapping("/csrf/token")
public class GenerateTokenController {
	
	@Autowired
	private TokenStore tokenStore ;
	
	@GetMapping("/create")
	public Object create() {
		String token = UUID.randomUUID().toString().replaceAll("-", "") ;
		tokenStore.store(token) ;
		return token ;
	}
	
}